<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <script type="text/javascript" src="../static/lib/html5shiv.js"></script>
    <script type="text/javascript" src="../static/lib/respond.min.js"></script>
    <script type="text/javascript" src="../static/lib/jquery/1.9.1/jquery.min.js"></script>
    <link rel="stylesheet" href="../static/h-ui/css/H-ui.css" />
    <link rel="stylesheet" href="../static/css/company.css" />
    <meta charset="UTF-8">
    <title>Edit BVO</title>
</head>
<body>
<article class="page-container">
    <div class="panel panel-default">

        <div class="panel-header">Edit Company Information</div>
        <div class="panel-body">
            <form action="" method="post" class="form form-horizontal" id="form-company-add">
                <div class="row cl">
                    <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>BVO username：</label>
                    <div class="formControls col-xs-8 col-sm-9">
                        <input type="text" class="input-text" value="" placeholder="" id="userName" name="userName">
                    </div>

                </div>
                <div class="row cl">
                    <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>BVO tel：</label>
                    <div class="formControls col-xs-8 col-sm-9">
                        <input type="text" class="input-text" value="" placeholder="" id="tel" name="tel">
                    </div>
                </div>
                <div class="row cl">
                    <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                        <button class="btn btn-primary-outline radius" id="btnback">&nbsp;&nbsp;返回&nbsp;&nbsp;</button>
                        <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                    </div>
                </div>
            </form>
        </div>
    </div>
</article>
<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="../static/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="../static/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="../static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="../static/h-ui.admin/js/H-ui.admin.js"></script> <!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="../static/lib/My97DatePicker/4.8/WdatePicker.js"></script>
<script type="text/javascript" src="../static/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="../static/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="../static/lib/jquery.validation/1.14.0/messages_zh.js"></script>

<script type="text/javascript">

    window.onload = load;
    var bvo = {}

    function getoldbvo(){
        var url = decodeURI(location.search); 			//获取url中"?"符后的字串 ('?aaa=123&bbb=456')
        console.log(url);
        var theRequest = {};
        if ( url.indexOf( "?" ) !== -1 ) {
            var str = url.substr( 1 ); 		//substr()方法返回从参数值开始到结束的字符串；
            var strs = str.split( "&" );
            for ( var i = 0; i < strs.length; i++ ) {
                theRequest[ strs[ i ].split( "=" )[ 0 ] ] = ( strs[ i ].split( "=" )[ 1 ]);
            }
            console.log( theRequest );		//此时的theRequest就是我们需要的参数；
            var urlValue;
            //这一步是我把获取的参数的值取出来，并附给变量，
            $.each(theRequest,function(index,val){
                urlValue = val;
            });
        }
        console.log(theRequest.userName);
        return theRequest;
    }

    function load(){
        var theRequest = getoldbvo();
        bvo = theRequest;
        $("#userName").attr("value",theRequest.userName);
        $("#tel").attr("value",theRequest.tel);

    }

    function getBvoInfo(){
        var username = $("#userName").val();
        var phonenumber = $("#tel").val();
        var bvoInfo = {
            'id':bvo.id,
            'username':username,
            'phonenumber':phonenumber,
        }
        console.log(bvoInfo)
        return bvoInfo;
    }

    $(function() {
        $("#btnback").click(function () {
            window.location.href = "/store/getbvoinfo";
        });


        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });

        $("#form-company-add").validate({
            rules: {
                userName:{
                    required:true,
                    minlength:1,
                    maxlength:50
                },tel:{
                    required:true,
                    maxlength:11,
                }
            },
            onkeyup: false,
            focusCleanup: true,
            success: "valid",
            submitHandler: function (form) {
                var bvoInfo = getBvoInfo();
                var url = "/store/updatebvo";
                $.ajax({
                    type: 'POST',
                    url: url,
                    data: JSON.stringify(bvoInfo),
                    contentType: "application/json",
                    dataType: 'json',
                    success: function () {
                        console.log("1111")
                        window.location.href="/store/getbvoinfo";
                    }
                });
            }
        });
    })

</script>

</body>
</html>